package com.ideyatech.errorhandling.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.ideyatech.errorhandling.entity.Issue;
import com.ideyatech.errorhandling.service.IssueService;

public class AddIssueController extends SimpleFormController {
	private String viewName;
	private IssueService issueService;
	
	@Override
	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		Issue issue = (Issue) command;
		issueService.addIssue(issue);
		return new ModelAndView(getSuccessView());
	}
	
	@Override
	protected boolean isFormSubmission(HttpServletRequest request) {
		String action = request.getMethod();
		if("POST".equalsIgnoreCase(action)){
			return true;
		}
		return false;
	}

	public void setIssueService(IssueService issueService) {
		this.issueService = issueService;
	}

	public IssueService getIssueService() {
		return issueService;
	}

	public String getViewName() {
		return viewName;
	}

	public void setViewName(String viewName) {
		this.viewName = viewName;
	}
	
}
